package com.example.ai.controller;

import com.example.ai.entity.ChatSession;
import com.example.ai.service.ChatHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chatHistory")
public class ChatHistoryController {

    @Autowired
    private ChatHistoryService chatHistoryService;

    /**
     * 创建对话
     *
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/createSession")
    public String createSession(@RequestHeader("X-User-Id") String userId) {
        return chatHistoryService.createSession(userId);
    }

    /**
     * 获取历史对话
     *
     * @param userId
     * @return
     */
    @GetMapping("/selectSessions")
    public List<ChatSession> selectSessions(@RequestHeader("X-User-Id") String userId) {
        return chatHistoryService.selectSessions(userId);
    }
}
